package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.QueueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xiaomi
 * @date: 2021/10/8
 * @description: 可以使用 FIFO 的队列完成秒杀，是公平的。
 */
@RestController
@RequestMapping("queue/fifo")
@Api(tags = "队列：FIFO")
@Slf4j
public class FIFOQueueController {

    @Autowired
    QueueService queueService;

    @GetMapping("/enqueue/{item}")
    @ApiOperation("元素入队")
    public boolean enqueue(@PathVariable("item") String item) {
        queueService.enqueue(item);
        return true;
    }


    @GetMapping("/dequeue")
    @ApiOperation("元素出队")
    public String dequeue() {
        String dequeue = queueService.dequeue();
        return dequeue;
    }

}
